#ifndef _DRIVER_HANDLE_H_
#define _DRIVER_HANDLE_H_
#include "global.h"
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <poll.h>
#include <sys/ioctl.h>
#include <string.h>

#define LED_GPIO_0 131
#define SR501_GPIO_0 115
#define CMD_TRIG  100

typedef int (*FUC_HANDLE)(void);

/*TODO 很草需要完善*/
typedef enum {
    direction_get = 0,
    direction_put = 1,
    direction_num = 2,
}DIRECTION;

typedef enum {
    cmd_open = 0,        /*开启*/
    cmd_close = 1,       /*关闭*/
    cmd_get_value = 2,   /*获取值*/
    cmd_no = 3,          /*无操作*/
    cmd_num = 4,
}CMD;

typedef enum {
    sr501_some = 1,
    sr501_nobody = 0,
    sr501_num = 2,
}SR501_STATUS;

typedef struct {
    int gpio;
    char device_name[32];
    union {  
        DIRECTION status;
    } led_direction;  
  
    union {  
        CMD command;  
    } led_cmd;
    FUC_HANDLE handle;
} LED;

typedef struct {
    int gpio;
    char device_name[32];
    FUC_HANDLE handle;
} SR501;

typedef struct{
    LED led;
    SR501 sr501;
}DRIVER;

/* TODO 后续使用相同的格式方便函数指针统一操作 */
int led_handle(DIRECTION led_direction, CMD *cmd);
int sr501_handle(int *data);
int sr04_handle(int *data);
int motor_handle(int data);
int irda_handle(char *data);
int dht11_handle(char *data);
int ds18b20_handle(char *data);
int at24c02_handle(DIRECTION direction, char *data, int len);
int dac_handle(int *data);

#endif/*driver_handle.h*/